<?php
/**
 * Created by PhpStorm.
 * User: miidi
 * Date: 2018/9/26
 * Time: 11:03
 */

namespace app\api\controller;


use app\api\model\Article;

class ArticleC
{
  public function editorArticle()
  {
    $articleModel = new Article();
    $data= request()->param();
//    $data = [
//        'id' => null,
//        'article' => $article
//    ];

    $result = $articleModel->save($data);
    if ($result) {
      return json_encode([
          'code' => 0,
          'message' => '发布成功！！'
      ]);
    }

  }

  public function getArticleById()
  {
    $id = input('id');
    $articleModel = new Article();
    $result = $articleModel->get($id);
    if ($result) {
      return json_encode([
          'code' => 0,
          'data' => $result
      ]);
    }
  }


  /**
   * 后台展示  分页处理
   * @url
   */
  public function getArticleAllList()
  {
    $page = input('page');
    $pageSize = input('pageSize');

    $query = Article::where(1)->order('update_time desc');
    $output = $query->paginate($pageSize, false, ['page' => $page]);
    return json($output);

  }

}